package com.example.server.web.controller;


import com.example.server.web.domain.Major;
import com.example.server.web.domain.RespBean;
import com.example.server.web.domain.dto.MajorParamDto;
import com.example.server.web.domain.page.PageQueryDto;
import com.example.server.web.service.MajorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yhj
 */
@RestController
@RequestMapping("/major")
@Api(tags = {"专业接口"})
public class MajorController {

    @Autowired
    private MajorService majorService;

    @ApiOperation(value = "添加专业信息")
    @PostMapping("/add")
    public RespBean add(@Validated @RequestBody Major major){
        Integer i = majorService.add(major);
        if(i!=1){
            return RespBean.error("添加失败！");
        }
        return RespBean.success("添加成功");
    }

    @ApiOperation(value = "分页查询专业信息")
    @GetMapping("/queryByPage")
    public RespBean queryByPage(MajorParamDto majorParamDto,PageQueryDto pageQueryDto){
        Map map = majorService.queryByPage(majorParamDto,pageQueryDto);
        return RespBean.success("查询成功",map);
    }

    @ApiOperation(value = "修改专业信息")
    @PostMapping("/modify")
    public RespBean modify(@RequestBody Major major){
        if(majorService.modify(major)){
            return RespBean.success("修改成功");
        }
        return  RespBean.error("修改失败");
    }

    @ApiOperation(value = "(单个或者多个)删除专业信息")
    @PostMapping("/deletes")
    public RespBean deletes(@RequestBody List<Integer> ids){
        Boolean b = majorService.deletes(ids);
        if(b){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
